/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>


bool isPrime(int num) {
    if (num < 2) return false;
    for (int i = 2; i <= num / 2; ++i) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
  
    std::unordered_map<std::string, int> wordToNumber = {
        {"zero", 0}, {"one", 1}, {"two", 2}, 
        {"three", 3}, {"four", 4}, {"five", 5},
        {"six", 6}, {"seven", 7}, {"eight", 8},
        {"nine", 9}
    };

    
    std::string word1, word2, word3;
    std::cin >> word1 >> word2 >> word3;

   
    if (word1.length() != 3 || word2.length() != 3 || word3.length() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

   
    int number = wordToNumber[word1] * 100 + wordToNumber[word2] * 10 + wordToNumber[word3];

    
    int closestPrime = number;
    while (true) {
        if (isPrime(closestPrime)) {
            break;
        } else {
            closestPrime--;
        }
    }

    std::cout << closestPrime << std::endl;

    return 0;
}